﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Data;
using MM.Common.Base;
using MM.Common.DBBase;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.Controls;
using DevExpress.Utils;
using System.Windows.Forms;

namespace MM.Common.UI.Controls
{
    public class UCComboFromDict : UCComboData
    {
        // Fields
        private string _DefaultData;
        private string _DT_Type;
        private RepositoryItemLookUpEdit cbProperties;
        private IContainer components;
        private RepositoryItemLookUpEdit ucProperties;

        // Methods
        public UCComboFromDict()
        {
            this._DT_Type = "";
            this._DefaultData = "";
            this.InitializeComponent();
        }

        public UCComboFromDict(IContainer container)
        {
            this._DT_Type = "";
            this._DefaultData = "";
            container.Add(this);
            this.InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        public override void Init()
        {
            base.Init();
            if (!base.DesignMode)
            {
                string commandtext = "SELECT DT_CODE ,DT_NAME ,INPUTCODE1 ,INPUTCODE2 ,DT_SORT FROM MXHLY_SYS_DICTIONARY \r\n   WHERE DT_TYPE = :type ORDER BY DT_SORT ";
                DataTable dt = new DataTable();
                SystemInfo.DbData.Retrieve(commandtext, new DataParamCol(new DataParam[] { new InputDataParam("type", this.DT_TYPE) }), ref dt);
                base.Properties.DataSource = dt;
            }
        }

        private void InitializeComponent()
        {
            UCComboBoxInputItem aItem = new UCComboBoxInputItem();
            UCComboBoxInputItem item2 = new UCComboBoxInputItem();
            UCComboBoxInputItem item3 = new UCComboBoxInputItem();
            UCComboBoxInputItem item4 = new UCComboBoxInputItem();
            this.ucProperties = new RepositoryItemLookUpEdit();
            this.cbProperties = new RepositoryItemLookUpEdit();
            this.ucProperties.BeginInit();
            this.cbProperties.BeginInit();
            base.SuspendLayout();
            this.ucProperties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.ucProperties.CloseUpKey = new KeyShortcut(Keys.Shift | Keys.F4);
            this.ucProperties.Name = "ucProperties";
            this.ucProperties.NullText = "";
            this.cbProperties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.cbProperties.CloseUpKey = new KeyShortcut(Keys.Shift | Keys.F4);
            this.cbProperties.Name = "cbProperties";
            this.cbProperties.NullText = "";
            base.ExistInputCode = true;
            aItem.FieldName = "INPUTCODE1";
            aItem.ItemName = "辅码1";
            aItem.ItemType = UCComboBoxInputItemType.InputCode1;
            aItem.ItemWidth = 30;
            item2.FieldName = "INPUTCODE2";
            item2.ItemName = "辅码2";
            item2.ItemType = UCComboBoxInputItemType.InputCode2;
            item2.ItemWidth = 30;
            item3.FieldName = "DT_CODE";
            item3.ItemName = "代码";
            item3.ItemType = UCComboBoxInputItemType.Data;
            item3.ItemWidth = 20;
            item4.FieldName = "DT_NAME";
            item4.ItemName = "名称";
            item4.ItemType = UCComboBoxInputItemType.Text;
            item4.ItemWidth = 40;
            base.ItemColumns.Add(aItem);
            base.ItemColumns.Add(item2);
            base.ItemColumns.Add(item3);
            base.ItemColumns.Add(item4);
            this.ucProperties.EndInit();
            this.cbProperties.EndInit();
            base.ResumeLayout(false);
        }

        // Properties
        [Category("MM附加"), Browsable(true), Description("本控件在新增时的缺省值"), DefaultValue("")]
        public string DefaultData
        {
            get
            {
                return this._DefaultData;
            }
            set
            {
                this._DefaultData = value;
            }
        }

        [Category("MM附加"), Browsable(true), Description("类型名"), DefaultValue("")]
        public string DT_TYPE
        {
            get
            {
                return this._DT_Type;
            }
            set
            {
                this._DT_Type = value;
            }
        }
    }
}
